import React, {Component} from 'react';
import { Image,View, Text,StyleSheet, } from 'react-native';
//import AutoHeightImage from 'react-native-auto-height-image';
 //import {CustomCachedImage} from "react-native-img-cache";
//import Image from 'react-native-image-progress';
//import ProgressBar from 'react-native-progress/Bar';

//https://github.com/wkh237/react-native-fetch-blob/wiki/Manually-Link-Package#user-content-link-ios-package
 //fix:Undefined is not an object(evaluating 'RNFetchBlob.DocumentDir

 export default class CImage extends Component {

    //构造函数
    constructor(props) {
        super(props);
        this.state = {
            errorcount:0,
            source:this.props.source,
            sourcebase:this.props.source,
            height:this.props.style.height,
            width:this.props.style.width,
        };
    }

    componentDidMount() {
    }

    //组件卸载
    componentWillUnmount() {

    }

    componentWillReceiveProps(nextProps) {
    }

    render() {
        return (
                <Image
                    {...this.props}
                    component={Image}
                    source={this.state.source}
                    errorcount={this.state.errorcount}
                    style={{...this.style,width:this.state.width,height:this.state.height}}
                    // indicator={ProgressBar.Pie} 
                    // indicatorProps={{
                    //     size: 40,
                    //     borderWidth: 0,
                    //     color: 'rgba(150, 150, 150, 1)',
                    //     unfilledColor: 'rgba(200, 200, 200, 0.2)'
                    //   }}
                    //threshold={0}
                    onLoad={()=>{
                        console.log("图片加载3:");
                    }
                    }
                    // renderError={()=>{
                    //     //console.log("图片加载失败3:");
                    // }}
                    //defaultSource={require('')}
                    onError={(e)=>{
                        if(this.state.width!=0&&this.state.height!=0)
                            {
                                this.setState({width:0,height:0});
                                console.log("图片加载失败2:重试:默认错误图片");
                            }
                        // this.state.errorcount=this.state.errorcount+1;
                        // if(this.state.errorcount>1)
                        // {
                        //     //this.setState({source:require(""),errorcount:this.state.errorcount});
                            
                        // }
                        // else
                        // {
                        //     this.setState({source:{uri:this.state.sourcebase.uri, cache: 'force-cache'},errorcount:this.state.errorcount});
                        //     console.log("图片加载失败2:重试:"+this.state.errorcount+"uri:"+this.state.sourcebase.uri+"error:"+e);
                        // }
                    }}
                    //defaultSource={{uri: require(''), width: 60, height: 60, scale: 1}}
                
                    />
        );
    }
}